#ifndef SOCKETDATA_H
#define SOCKETDATA_H

#include <QTcpSocket>

#include "core/Constans.h"

class SocketData
{
public:
    SocketData(QTcpSocket *socket);
    virtual ~SocketData();

    QTcpSocket * getSocket() { return socket; }

    quint32 getSize();
    void prepareDataBuff();

    uchar * getDataBuff() { return dataBuff; }
    uchar * getSizeBuff() { return sizeBuff; }

    int getSizeBuffRead() { return sizeBuffRead; }
    int getDataBuffRead() { return dataBuffRead; }

    void increaseSizeBuffRead(int value) { sizeBuffRead += value; }
    void increaseDataBuffRead(int value) { dataBuffRead += value; }

    bool isSizeRead() { return sizeBuffRead == PACKET_LENGTH_BYTE_SIZE; }
    bool isDataRead() { return getSize() == dataBuffRead; }

    void resetReadBytesCount() { sizeBuffRead = dataBuffRead = 0; }

    QString getListenAddress() { return listenAddress; }
    quint16 getListenPort() { return listenPort; }
    void setListenAddress(QString listenAddress) { this->listenAddress = listenAddress; }
    void setListenPort(quint16 listenPort) { this->listenPort = listenPort; }
private:
    QTcpSocket *socket;

    QString listenAddress;
    quint16 listenPort;

    uchar *dataBuff, sizeBuff[PACKET_LENGTH_BYTE_SIZE];
    quint32 sizeBuffRead, dataBuffRead;
};

#endif // SOCKETDATA_H
